/**
 * 用户个人信息接口测试用例
 *
 * Created by snowingsea on 2020/02/03.
 */
const chai = require('chai');
const should = chai.should(); // eslint-disable-line no-unused-vars
chai.use(require('chai-http'));

const common = require('./../common');
const Administrator = require('./../../models/administrator');
const uri = require('./../uri');
const { statusKind } = require('./../../../phoenix/models/users');

module.exports = describe('/GET me.json', function () {
  const url = '/me.json';
  const administrator = new Administrator();
  const newUserIds = [];
  let user = {};

  before(function (done) {
    administrator.createRandomUser()
      .then((res) => {
        user = res;
        newUserIds.push(user.userId);
        done();
      })
      .catch(done);
  });
  after(function (done) {
    administrator.removeUsers(newUserIds)
      .then(() => {
        done();
      })
      .catch(done);
  });

  common.should.be.user(uri, url, 'get');

  // 正常请求
  it('it should GET my information', function (done) {
    user.login()
      .then(() => {
        chai.request(uri)
          .get(url)
          .set('Authorization', `Bearer ${user.token.accessToken}`)
          .end((err, res) => {
            res.should.have.status(200);
            common.should.be.userMessage(res.body);
            res.body.userId.should.be.eql(user.userId);
            res.body.username.should.be.eql(user.username);
            res.body.nickname.should.be.eql(user.nickname);
            res.body.role.should.be.eql(user.role);
            res.body.lang.should.be.eql(user.lang);
            res.body.status.should.be.eql(statusKind.online);
            done();
          });
      })
      .catch(done);
  });
});
